﻿@namespace Aspire.Dashboard.Components

@using System.Collections.Concurrent
@using Aspire.Dashboard.Resources

@inject IStringLocalizer<ControlsStrings> ControlsStringsLoc

<FluentStack Orientation="Orientation.Vertical">
    <FluentCheckbox Label="@ControlsStringsLoc[nameof(ControlsStrings.LabelAll)]"
                    ThreeState="true"
                    ShowIndeterminate="false"
                    ThreeStateOrderUncheckToIntermediate="true"
                    @bind-CheckState:get="@AreAllTypesVisible()"
                    @bind-CheckState:set="@OnAllResourceTypesCheckedChangedAsync"
                     />
    @foreach (var (resourceType, _) in AllResourceTypes)
    {
        var isChecked = VisibleResourceTypes.ContainsKey(resourceType);
        <FluentCheckbox Label="@resourceType"
                        @bind-Value:get="@isChecked"
                        @bind-Value:set="@(c => OnResourceTypeVisibilityChangedAsync(resourceType, c))" />
    }
</FluentStack>
@code {
    [Parameter, EditorRequired]
    public required ConcurrentDictionary<string,bool> AllResourceTypes { get; set; }

    [Parameter, EditorRequired]
    public required Func<bool?> AreAllTypesVisible { get; set; }

    [Parameter, EditorRequired]
    public required ConcurrentDictionary<string,bool> VisibleResourceTypes { get; set; }

    [Parameter, EditorRequired]
    public required Func<bool?, Task> OnAllResourceTypesCheckedChangedAsync { get; set; }

    [Parameter, EditorRequired]
    public required Func<string, bool,Task> OnResourceTypeVisibilityChangedAsync { get; set; }
}
